﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Student_updateInfo.aspx.cs" Inherits="scmsByAspdNet.Student_updateInfo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>修改个人信息</title>
    <link rel="stylesheet" href="static/bootstrap-4.6.0/css/bootstrap.css" />
    <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.css" />
    <script src="static/js/jquery-3.6.0.js"></script>
    <script src="static/js/jquery-3.6.0.min.js"></script>
</head>
<body>
    <%-- 导航栏 --%>
    <div class="nav-warp">
        <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
            <a class="navbar-brand" href="Student.aspx">学生选课系统-学生界面</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>

            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-expanded="false">更多功能
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                            <a class="dropdown-item" href="#">相关信息</a>
                            <a class="dropdown-item" href="#">关于我们</a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="#">版本有关</a>
                        </div>
                    </li>
                </ul>
                <ul class="navbar-nav ml-auto">
                    <li class="nav-item">
                        <a id="sign-out" class="nav-link" href="./Login.aspx" tabindex="-1" aria-disabled="true" style="color: red;">退出登录</a>
                    </li>
                </ul>
                <form class="form-inline my-2 my-lg-0">
                    <input class="form-control mr-sm-2" type="search" placeholder="没有任何功能" aria-label="Search" />
                    <button class="btn btn-outline-success my-2 my-sm-0 loginSubmit" type="submit">Search</button>
                </form>
            </div>
        </nav>
    </div>
    <div id="update_box" style="width: 400px; margin: 0px auto">

    </div>
</body>
    <script src="//cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="static/bootstrap-4.6.0/js/bootstrap.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.js"></script>
    <script>
    init_update_box();
    function init_update_box() {
        //获取数据
        $.post("cotro/student/getAllStudent.ashx", {

        }, function (res, status) {
            if (status == "success") {
                res = JSON.parse(res);
                if (true) {
                    for (let i = 0; i < res.rows.length; ++i) {
                        //$.cookie('indiv_id')
                        if (res.rows[i].id == $.cookie('indiv_id')) {
                            let update_box = document.getElementById("update_box");
                            update_box.innerHTML = `<h1>修改个人信息</h1>
                                                    <form>
                                                        <div class="form-group">
                                                            <label for="stu_id">ID</label>
                                                            <input type="text" class="form-control" id="stu_id" disabled="true" value="${res.rows[i].id}"/>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="stu_name">姓名</label>
                                                            <input type="text" class="form-control" id="stu_name" value="${res.rows[i].name}"/>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="stu_faculty">学院</label>
                                                            <input type="text" class="form-control" id="stu_faculty" value="${res.rows[i].faculty}"/>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="stu_class">班级</label>
                                                            <input type="text" class="form-control" id="stu_class" value="${res.rows[i].class}"/>
                                                        </div>
                                                        <button type="button" class="btn btn-danger" onclick="updateInfo()">确认修改</button>
                                                    </form>`
                            break;
                        }
                    }
                }
            }
        })
    }
    function updateInfo() {
        $.post("cotro/student/updateStudentInfo.ashx", {
            id: $("#stu_id").val(),
            name: $("#stu_name").val(),
            faculty: $("#stu_faculty").val(),
            class: $("#stu_class").val(),
        }, function (res, status) {
            if (status == "success") {
                res = JSON.parse(res);
                if (res.line == "1") {
                    alert("修改成功");
                } else {
                    alert("修改失败")
                }
            }
        })
    }
    </script>
</html>
